package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Region;
import cn.wolfcode.wolf2w.query.RegionQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IRegionService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Controller
@RequestMapping("region")
public class RegionController {

    @Autowired
    private IRegionService regionService;

    @Autowired
    private IDestinationService destinationService;

    //页面数据和分页
    @RequestMapping("/list")
    public String List(Model model, @ModelAttribute("qo") RegionQuery qo) {
        Page<Region> page = regionService.query(qo);
        model.addAttribute("page", page);
        return "region/list";
    }



    //关联目的地下拉框数据
    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests() {
        return destinationService.list();
    }




    //保存或修改
    @PostMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Region region) {
        regionService.saveOrUpdate(region);
        return JsonResult.success();
    }


    //通过id查询目的地(关联地区)
    @GetMapping("/getDestByRegionId")
    @ResponseBody
    public Object getDestByRegionId(String rid){
        List<Destination> list = destinationService.querygetDestByRegionId(rid);
        return list;
    }

    //设置或取消热门操作(ishot)
    @GetMapping("/changeHotValue")
    @ResponseBody
    public Object changeHotValue(String id ,int hot){
        regionService.changeHotValue(id,hot);
        return JsonResult.success();
    }

    //删除
    @GetMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        regionService.delete(id);
        return JsonResult.success();
    }


    //查询攻略分类添加下的关联目的地
    @GetMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(int deep){
        return destinationService.list();
    }
}
